package com.freewill.gcm;

import android.app.KeyguardManager;
import android.content.Context;
import android.os.PowerManager;
import android.util.Log;

public class MessageWakeLock {
	
	private static PowerManager.WakeLock sCpuWakeLock;
    private static KeyguardManager.KeyguardLock mKeyguardLock;
    private static boolean isScreenLock;
    
    static void acquireWakeLock(Context context){
    	
    	if (sCpuWakeLock != null) {
            return;
        }
    	
    	PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    	
    	Log.d("mkkim", "test4 MessageWakeLock : acquireWakeLock : ");
    	
    	if(!pm.isScreenOn()){
	   		 sCpuWakeLock = pm.newWakeLock(
	   	             PowerManager.SCREEN_BRIGHT_WAKE_LOCK |
	   	             PowerManager.ACQUIRE_CAUSES_WAKEUP |
	   	             PowerManager.ON_AFTER_RELEASE, "MessageWakeLock");
	   	     sCpuWakeLock.acquire();
    	}
    }
    
    static void releaseCpuLock(Context context) {
        Log.e("mkkim", "test4 releaseCpuLock cpu wake lock  :sCpuWakeLock : "+sCpuWakeLock);
        
        if(sCpuWakeLock==null){
        	PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
        	sCpuWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MessageWakeLock"); 
        	sCpuWakeLock.acquire();
        }
        
        if (sCpuWakeLock != null) {
            sCpuWakeLock.release();
            sCpuWakeLock = null;
        }
    }
}
